package com.vint.leetcode;

import com.vint.common.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/*
 * 1. done
 * 2. easy
 * 3. tree，递归
 * 求一棵树所有左叶子的和
 */
public class Leetcode404 {
    public int sumOfLeftLeaves(TreeNode root) {
        if(null==root){
            return 0;
        }
        if(null==root.left){
            return sumOfLeftLeaves(root.right);
        }
        if(null!=root.left&&root.left.left==null&&root.left.right==null){
            return root.left.val + sumOfLeftLeaves(root.right);
        }
        return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
    }
    public static void main(String[] args) {
        Leetcode404 leetcode404 = new Leetcode404();
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.left.left = new TreeNode(5);
        root.right = new TreeNode(4);
        root.right.right= new TreeNode(2);
        System.out.println(leetcode404.sumOfLeftLeaves(root));
    }
  }
